package com.lykj.gm.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;

import com.lykj.gm.bean.LoginInfo;

public class CSVUtils {

	public static List<LoginInfo> loadCsvData(File file) {
		List<LoginInfo> dataList = new ArrayList<LoginInfo>();
		
		BufferedReader br = null;
		try {
			br = new BufferedReader(new FileReader(file));
			String line = "";
			while( (line = br.readLine()) != null ) {
				String[] temp = line.split(",");
				LoginInfo info = new LoginInfo(temp[0], temp[1]);
				dataList.add(info);
			}
		} catch (Exception e) {
			// TODO: handle exception
		} finally {
            if( br != null){
                try {
                    br.close();
                    br = null;
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
		
		
		
		return dataList; 
	}
	
	public static void main(String[] args) throws IOException {
		List<LoginInfo> dataList = CSVUtils.loadCsvData(new File(new File(".").getCanonicalPath()+"\\" 
				+ "data/info.csv"));
        if(dataList!=null && !dataList.isEmpty()){
            for(LoginInfo data : dataList){
                System.out.println(data);
            }
        }
	}
}
